<?php

namespace app\dao\goods;

use app\dao\BaseDao;
use app\model\ShopCategory;

class ShopCategoryDao extends BaseDao
{
    public function updateById($id, array $updateList)
    {
        $this->getModel()->where('id', '=', $id)->update($updateList);
    }

    public function getAllByType($type, $shop_id)
    {
        $query = $this->getModel()->where(['type' => $type, 'shop_id' => $shop_id]);
        return [
            'pagination' => ['page' => 1, 'perPage' => -1, 'total' => $query->count()],
            'list'       => $query->select()
        ];
    }

    public function deleteById($id)
    {
        $this->getModel()->destroy($id);
    }

    public function getLevelByParentId($parent_id)
    {
        return $this->getModel()->where('id', '=', $parent_id)->field('level')->find();
    }

    protected function setModel(): string
    {
        return ShopCategory::class;
    }

    public function getById($id)
    {
        return $this->getModel()->find($id);
    }
}